'use strict';

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.sequelize.transaction((t) => {
      return Promise.all([
          queryInterface.addColumn('CartItems', 'price', {
              type: Sequelize.INTEGER
          }, { transaction: t }),
          queryInterface.addColumn('CartItems', 'currency', {
            type: Sequelize.STRING,
          }, { transaction: t }),
          queryInterface.addColumn('CartItems', 'ProductId', {
            type: Sequelize.INTEGER,
            references: {
              model: 'Products', // name of Target model
              key: 'id', // key in Target model that we're referencing
            },
            onUpdate: 'CASCADE',
            onDelete: 'SET NULL',
          }, { transaction: t }),
      ])
    })
  },

  down: (queryInterface, Sequelize) => {
    return queryInterface.sequelize.transaction((t) => {
      return Promise.all([
          queryInterface.removeColumn('CartItems', 'price',
           { transaction: t }),
          queryInterface.removeColumn('CartItems', 'currency',
           { transaction: t }),
           queryInterface.removeColumn('CartItems', 'ProductId',
           { transaction: t }),
          //  queryInterface.removeColumn('CartItems', 'cartId',
          //  { transaction: t })
      ])
    })
  }
};
